package com.example.qxfw.hbqx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.qxfw.common.entity.qx.SatelliteNephoram3;
import com.example.qxfw.common.entity.zy.AirPollution;
import com.example.qxfw.common.entity.zy.EnviroStation;
import com.example.qxfw.common.entity.zy.SumAtmosphericDayData;
import com.example.qxfw.hbqx.mapper.AirPollutionMapper;
import com.example.qxfw.hbqx.mapper.SatelliteNephoram3Mapper;
import com.example.qxfw.hbqx.mapper.SumAtmosphericDayDataMapper;
import com.example.qxfw.hbqx.service.HjjcService;
import com.example.qxfw.ybzz.mapper.EnviroStationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class HjjcServiceImpl implements HjjcService {
    @Autowired
    private SumAtmosphericDayDataMapper sumAtmosphericDayDataMapper;
    @Autowired
    private AirPollutionMapper airPollutionMapper;
    @Autowired
    private EnviroStationMapper enviroStationMapper;
    @Autowired
    private SatelliteNephoram3Mapper satelliteNephoram3Mapper;


    @Override
    /**
     *根据时间段查询空气逐小时实况空气质量日统计表
     * @param observtimeStart 起始时间
     * @param observtimeEnd 终止时间
     * @return
     */
    public List<SumAtmosphericDayData> selectOrderByObservtimePeriodOfSumAtmosphericDayData(Date observtimeStart, Date observtimeEnd) {
        return sumAtmosphericDayDataMapper.selectOrderByObservtimePeriodOfSumAtmosphericDayData(observtimeStart,observtimeEnd);
    }

    @Override
    /**
     *根据时间段查询空气逐小时实况
     * @param observtimeStart 起始时间
     * @param observtimeEnd 终止时间
     * @return
     */
    public List<AirPollution> selectByTimePeriodAirPollution(Date observtimeStart, Date observtimeEnd) {
        return airPollutionMapper.selectByTimePeriodAirPollution(observtimeStart, observtimeEnd);
    }

    /**
     * 根据开始时间查询空气逐小时实况
     * @param observtimeStart 开始时间
     * @return
     */
    @Override
    public List<AirPollution> selectByTimeOfAirPollution(Date observtimeStart) {
        return airPollutionMapper.selectByTimeOfAirPollution(observtimeStart);
    }

    /**
     * 根据站点和时间段查询空气质量日统计表
     * @param observtimeStart 起始时间
     * @param observtimeEnd 终止时间
     * @param stationid 站点编号
     * @return
     */
    @Override
    public List<SumAtmosphericDayData> selectByObservtimeAndstationid(Date observtimeStart, Date observtimeEnd, String stationid) {
        return sumAtmosphericDayDataMapper.selectByObservtimeAndstationid(observtimeStart, observtimeEnd, stationid);
    }

    /**
     * 根据站点和开始时间查询空气质量日统计表
     * @param observtimeStart 开始时间
     * @return
     */
    @Override
    public List<SumAtmosphericDayData> selectByTimeOfSumAtmosphericDayData(Date observtimeStart) {
        return sumAtmosphericDayDataMapper.selectByTimeOfSumAtmosphericDayData(observtimeStart);
    }

    /**
     *降序查询所有观测时间，并只显示一条
     * @return
     */
    @Override
    public List<AirPollution> selectByObservtime() {
        return airPollutionMapper.selectByObservtime();
    }

    /**
     * 通过城市获取环境监测站点信息
     * @param city
     * @return
     */
    @Override
    public List<EnviroStation> selectByCity(String city) {
        return enviroStationMapper.selectByCity(city);
    }

    /**
     * 通过城市获取环境监测站点名字
     * @param city
     * @return
     */
    @Override
    public List<EnviroStation> selectByCity1(String city) {
        return enviroStationMapper.selectByCity1(city);
    }

    /**
     *从 AirPollution 表中获取除了 StationID 为 'stationid' 的最近3个不重复的 observTime 时间字段，并按降序排序。
     * @param stationid 站点id
     * @return
     */
    @Override
    public List<AirPollution> selectByNotStationid(String stationid) {
        return airPollutionMapper.selectByNotStationid(stationid);
    }

    /**
     * 获取在规定时间段中非stationid的观测时间
     * @param observtimeStart 观测时间起点
     * @param observtimeEnd 观测时间终点
     * @param stationid 站点id
     * @return
     */
    @Override
    public List<AirPollution> selectByObservtimeAndNotStationid(Date observtimeStart, Date observtimeEnd, String stationid) {
        return airPollutionMapper.selectByObservtimeAndNotStationid(observtimeStart, observtimeEnd, stationid);
    }

    /**
     * 获取除了stationid以外的站点的观测时间
     * @param stationid 站点id
     * @return
     */
    @Override
    public List<SumAtmosphericDayData> getObservtimeByNotStationId(String stationid) {
        return sumAtmosphericDayDataMapper.getObservtimeByNotStationId(stationid);
    }

    /**
     * 获取在规定时间段中非stationid的观测时间,升序
     * @param observtimeStart 观测时间起点
     * @param observtimeEnd 观测时间终点
     * @param stationid 站点id
     * @return
     */
    @Override
    public List<SumAtmosphericDayData> getByObservtimeAndNotStationid(Date observtimeStart, Date observtimeEnd, String stationid) {
        return sumAtmosphericDayDataMapper.getByObservtimeAndNotStationid(observtimeStart, observtimeStart, stationid);
    }

    /**
     * 获取所有空气质量日统计表信息
     * @return
     */
    @Override
    public List<SumAtmosphericDayData> getAllOfSumAtmosphericDayData() {
        return sumAtmosphericDayDataMapper.selectList(null);
    }

    /**
     * 根据元素和时间段获取空气质量日统计表信息
     * @param observtimeStart 开始时间
     * @param observtimeEnd 结束时间
     * @param element 元素
     * @return
     */
    @Override
    public List<SumAtmosphericDayData> getByTimePeriodAndElementOfSumAtmosphericDayData(Date observtimeStart, Date observtimeEnd, String element) {
        return sumAtmosphericDayDataMapper.getByTimePeriodAndElementOfSumAtmosphericDayData(observtimeStart, observtimeEnd, element);
    }

    /**
     * 根据元素和时间点获取空气质量日统计表信息
     * @param observtime 开始时间
     * @param element 元素
     * @return
     */
    @Override
    public List<SumAtmosphericDayData> getByTimeAndElementOfSumAtmosphericDayData(Date observtime, String element) {
        return sumAtmosphericDayDataMapper.getByTimeAndElementOfSumAtmosphericDayData(observtime, element);
    }

    /**
     * 根据元素和时间段获取空气逐小时实况信息
     * @param observtimeStart 开始时间
     * @param observtimeEnd 结束时间
     * @param element 元素
     * @return
     */
    @Override
    public List<AirPollution> getByTimePeriodAndElementOfAirPollution(Date observtimeStart, Date observtimeEnd, String element) {
        return airPollutionMapper.getByTimePeriodAndElementOfAirPollution(observtimeStart, observtimeEnd, element);
    }

    /**
     * 根据元素和时间点空气逐小时实况信息
     * @param observtime 开始时间
     * @param element 元素
     * @return
     */
    @Override
    public List<AirPollution> getByTimeAndElementOfAirPollution(Date observtime, String element) {
        return airPollutionMapper.getByTimeAndElementOfAirPollution(observtime, element);
    }

    /**
     * 根据时间段查询风云3号卫星云图
     * @param datecharStart 开始时间
     * @param datecharEnd 结束时间
     * @return
     */
    @Override
    public List<SatelliteNephoram3> selectByTimePeriodOfSatelliteNephoram3(Date datecharStart, Date datecharEnd) {
        return satelliteNephoram3Mapper.selectList(new LambdaQueryWrapper<SatelliteNephoram3>()
        .between(SatelliteNephoram3::getDatechar, datecharStart, datecharEnd));
    }











}
